package com.masterclient.app.businessmodule.minemodule.index.tutor;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.eoner.middlelib.router.map.FCRouterPath;
import com.masterclient.app.R;
import com.masterclient.app.base.FCBusinessActivity;

import butterknife.BindView;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation;

/**
 * 作者：sean
 * 创建时间：2017/7/19 15:30
 * 功能说明：
 */
@Route(path = FCRouterPath.TUTOR_PATH)
public class MyTutorActivity extends FCBusinessActivity<MyTutorPresenter> implements MyTutorContract.View {

    @BindView(R.id.iv_user_head)
    ImageView ivUserHead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_wx_number)
    TextView tvWxnumber;
    @BindView(R.id.iv_copy_phone)
    ImageView ivCopyPhone;
    @BindView(R.id.iv_copy_wx_number)
    ImageView ivCopyWxNumber;

    private MyTutorBean myTutorBean;

    @Override
    protected int requireGetLayoutId() {
        return R.layout.activity_my_tutor;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setTitle("我的导师");
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {
        mPresenter.getTutorInfo();
    }

    @OnClick({R.id.iv_copy_phone,R.id.iv_copy_wx_number})
    void onClick(View view){
        switch (view.getId()){
            case R.id.iv_copy_phone:
                if (!TextUtils.isEmpty(myTutorBean.mobile)){
                    ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setPrimaryClip(ClipData.newPlainText(null, myTutorBean.mobile));
                    showToast("已复制到粘贴板");
                }                break;
            case R.id.iv_copy_wx_number:
                if (!TextUtils.isEmpty(myTutorBean.wechat)){
                    ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setPrimaryClip(ClipData.newPlainText(null, myTutorBean.wechat));
                    showToast("已复制到粘贴板");
                }
                break;
                default:
        }
    }

    @Override
    public void getTutorInfoSuccess(MyTutorBean bean) {
        if (bean != null){
            myTutorBean = bean;
            ViewTransformUtil.glideImageView(this,bean.headImgurl,ivUserHead,
                    new CropCircleWithBorderTransformation(0,0x0A3D2529), R.mipmap.user_head_default_icon);
            if (TextUtils.isEmpty(bean.nickName)){
                tvName.setText("无");
            }else {
                tvName.setText(bean.nickName);
            }
            if (TextUtils.isEmpty(bean.mobile)){
                tvPhone.setText("无");
                ivCopyPhone.setVisibility(View.GONE);
            }else {
                tvPhone.setText(bean.mobile);
                ivCopyPhone.setVisibility(View.VISIBLE);
            }
            if (TextUtils.isEmpty(bean.wechat)){
                tvWxnumber.setText("无");
                ivCopyWxNumber.setVisibility(View.GONE);
            }else {
                tvWxnumber.setText(bean.wechat);
                ivCopyWxNumber.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void getTutorInfoFail(String msg) {
        ToastUtil.showToast(msg);
    }
}
